#include "state.h"

void morningstate::studystate(studytime *p_time)
{
	if (NULL != p_time)
	{
		if (MOON > p_time->getcurtime())
		{
			cout << "current time: " << p_time->getcurtime() << " clock: moring study!" << endl;
		}
		else
		{
			p_time->setstate(new noonstate());
			p_time->studystate();
		}
	}
}

void noonstate::studystate(studytime *p_time)
{
	if (NULL != p_time)
	{
		if (AFTERNOON > p_time->getcurtime())
		{
			cout << "current time: " << p_time->getcurtime() << " clock: noon study!"  << endl;
		}
		else
		{
			p_time->setstate(new afternoonstate());
			p_time->studystate();
		}
	}
}

void afternoonstate::studystate(studytime *p_time)
{
	if (NULL != p_time)
	{
		if (EVENING > p_time->getcurtime())
		{
			cout << "current time: " << p_time->getcurtime() << " clock: evening study!" << endl;
		}
		else
		{
			p_time->setstate(new eveningstate());
			p_time->studystate();
		}
	}
}

void reststate::studystate(studytime *p_time)
{
	if (NULL != p_time)
	{
		cout << "current time: " << p_time->getcurtime() << " clock: rest." << endl;
	}
}

void sleepstate::studystate(studytime *p_time)
{
	if (NULL != p_time)
	{
		cout << "current time: " << p_time->getcurtime() << " clock: sleep." << endl;
	}
}

void eveningstate::studystate(studytime *p_time)
{
	if (NULL != p_time)
	{
		if (p_time->isstudyfinished())
		{
			p_time->setstate(new reststate());
			p_time->studystate();
		}
		else
		{
			if (NIGHT > p_time->getcurtime())
			{
				cout << "current time: " << p_time->getcurtime() << " clock, evening study!" << endl;
			}
			else
			{
				p_time->setstate(new sleepstate());
				p_time->studystate();
			}
		}
	}
}

